﻿#pragma once

#include <QObject>
#include "GlobalDefine.h"

class CoreData  : public QObject
{
	Q_OBJECT

public:
	static CoreData& getInstance() {
		static CoreData instance; // This will be created once and only once
		return instance;
	}

	static SerialPortInfo m_serialPortInfo;
	static BatteryInfoRom m_batteryInfo;
	static BatteryDetailInfoRom m_batteryDetailInfo;
	static ProtectParamInfo m_protectParamInfo;
	static FactoryParamInfo m_factoryParamInfo;
	static QByteArray _nowStationAddress;

	static const BatteryInfoRom &getBatteryInfo();
	static const BatteryDetailInfoRom &getBatteryDetailInfo();

	//密钥
	static QString generatePasswordFromMacAddress()
	{
		// 获取本机的MAC地址
		QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
		QString macAddress;

		foreach(QNetworkInterface interface, interfaces)
		{
			macAddress = interface.hardwareAddress();
			if (!macAddress.isEmpty())
				break;
		}

		if (macAddress.isEmpty())
		{
			qWarning() << "Failed to retrieve MAC address.";
			return QString();
		}

		// 计算MAC地址的SHA-256散列值
		QByteArray macData = macAddress.toUtf8();
		QByteArray hashData = QCryptographicHash::hash(macData, QCryptographicHash::Sha256);

		// 将散列值转换为十六进制表示的密码
		QString password = hashData.toHex();

		return password;
	};

private:
	CoreData(QObject *parent = nullptr);
	~CoreData();

	static QString m_password;


	// Disable copy constructor and assignment operator
	CoreData(const CoreData&) = delete;
	CoreData& operator=(const CoreData&) = delete;

//private:
// 	static BatteryInfoRom CoreData::m_batteryInfo;
// 	static BatteryDetailInfoRom CoreData::m_batteryDetailInfo;
};

